package com.yadang.admin.controller;


import com.yadang.admin.entity.LitemallAd;
import com.yadang.admin.entity.User;
import com.yadang.admin.log.Log;
import com.yadang.admin.service.ILitemallAdService;
import com.yadang.admin.service.ILitemallRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/test")
@Api(tags = {"测试接口"})
public class TestController {

    @Autowired
    private ILitemallAdService litemallAdService;


    @Autowired
    private ILitemallRoleService litemallRoleService;


    @PostMapping("/dd")
    @ApiOperation(value = "查询接口", httpMethod = "POST", notes = "查询接口")
    @Log(value = "查询操作", type = Log.LogType.SELECT)
    public List<LitemallAd> test(@RequestBody LitemallAd litemallAd) {
        List<LitemallAd> litemallAds = null;
        try {
            litemallAds = litemallAdService.getBaseMapper().selectList(null);
            //litemallAdService.addLitemallAd();
            System.out.println("1111");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return litemallAds;
    }

    @GetMapping("/login")
    public String test(String name, String pwd) {
        String rt = null;
        try {
            Subject subject = SecurityUtils.getSubject();
            UsernamePasswordToken token = new UsernamePasswordToken(name, pwd);
            subject.login(token);
            // 存放查询出来的user
            User user = (User) subject.getPrincipal();
            rt = "success";
        } catch (Exception e) {
            rt = "fail";
            e.printStackTrace();
        }

        return rt;
    }
}
